package io.github.ilkgunel.dao;

import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.model.Filters;
import io.github.ilkgunel.database.AccessMongoDB;
import io.github.ilkgunel.pojo.Student;
import org.bson.Document;
import org.bson.conversions.Bson;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class test2_3 {
    public List<Student> find()
    {
        List<Student> list = new ArrayList<>();
        //FindIterable<Document> result = getMongoDatabase().getCollection("Records").find(new Document("name","Can"));
        AccessMongoDB accessMongoDB = new AccessMongoDB();



        FindIterable<Document> result = accessMongoDB.getCollection("student").find();


        MongoCursor<Document> cursor = result.iterator();
        while (cursor.hasNext()) {

            Document document = cursor.next();

           /* System.out.println(document.get("_id").toString());
            System.out.println(new BigDecimal((document.get("sid")).toString()).toPlainString());
            System.out.println(document.get("name").toString());
            System.out.println( document.get("sex").toString());
            String temp= new BigDecimal((document.get("age")).toString()).toPlainString();
            System.out.println((int)Double.parseDouble( temp));
            System.out.println(document.get("birthday").toString());
            System.out.println(document.get("dname").toString());
            temp= new BigDecimal((document.get("class")).toString()).toPlainString();
            System.out.println((int) Double.parseDouble( temp));
*/
            String temp;
            Student s=new Student();
            s.set_id(document.get("_id").toString());

            s.setSid( new BigDecimal((document.get("sid")).toString()).toPlainString());
            s.setName(document.get("name").toString());
            s.setSex( document.get("sex").toString());

            temp= new BigDecimal((document.get("age")).toString()).toPlainString();
            s.setAge((int)Double.parseDouble( temp));

            s.setBirthday( document.get("birthday").toString());
            s.setDname( document.get("dname").toString());

            s.setTheclass( document.get("class").toString());


           /* Address address1 = new Address();
            address1.setStreet(( address.get("street"));
            address1.setBorough((String) address.getString("borough"));
            address1.setCity((String) address.getString("city"));

            Record record = new Record();
            record.setId(document.get("_id").toString());
            record.setName((String) document.get("name"));
            record.setSurname((String) document.get("surname"));
            record.setAddress(address1);
*/
            list.add(s);
        }
        return list;
    }
}
